normal
Statistics Mar10 Timm Revised

How to Find a Normal Distribution

Problem
=======

You a sampling a normal population.
How to find the mean and standard deviation of that population?

Solution
========

Keep the sum of the sample,
the sum of the squares of the sample, and 
the size of the sample.

 function nkeep(x,m) {
     m["n"]++;
     m["s"]  += x
     m["s2"] += x^2
 }
 function nmean(m) {
     return m["s"] / m["n"]
 }
 function nsd(m) {
     return sd(m["s2"],m["s"],m["n"])
 }
 function sd(sumSq,sumX,n) {
     return sqrt((sumSq-((sumX*sumX)/n))/(n-1));
 }

Example
=======

 function Nkeep(   i,m) {
     for(i=1;i<=30;i++)
         nkeep(i,m)
     print nmean(m), nsd(m);
 }

Author
======

by Tim Menzies

